import {
    _get,
    _post
} from '../../../utils/request'
import util from '../../../utils/util'
import { debounce, throttle } from "../../../utils/debounce";
const app = getApp()

Page({
    data: {

        gongdan0: [{
                label: "工单编号",
                content: "016431354",
            },
            {
                label: "工程名称",
                content: "杭州九链科技",
            },
            {
                label: "建设单位",
                content: "杭州九链科技",
            },
            {
                label: "建设单位地址",
                content: "信息产业园",
            },
            {
                label: "设计施工单位",
                content: "杭州九链科技",
            },
            {
                label: "设计施工单位地址",
                content: "信息产业园",
            },
            {
                label: "委托单位",
                content: "方圆检测",
            },
            {
                label: "委托单位地址",
                content: "xxxx",
            },

            {
                label: "受检单位",
                content: "杭州九链科技",
            },
            {
                label: "受检单位地址",
                content: "杭州九链科技",
            },
            {
                label: "检验项目",
                content: "电脑设备",
            },
        ],
        gongdan: [],
        title: '',
        address: ''
    },
    showAddress() {
        let that = this
        dd.getLocation({
            success(res) {
                that.setData({
                    address: res.address
                })
                console.log(res);

            },
            fail() {
                dd.alert({ title: '定位失败' });
            },
        })
    },
    getConfirm() {
        _get(`/myTest/selectTestResultByWorkerId`, { workerId: app.test_id }).then(res => {

            app.testConfirmId = res.data.data.workerOrderResultId
            let that = this
            dd.getLocation({
                success(res1) {
                    // 这里this指向的是这个参数对象
                    res.data.data.location = res1.address
                    that.setData({
                            title: res.data.title,
                            gongdan: res.data.data,
                            workerOrderResultId: res.data.data.workerOrderResultId
                        })
                        // console.log(res1);
                },
                fail() {
                    dd.alert({ title: '定位失败' });
                },
            })

            console.log('检测结果封面', this.data.gongdan);
        })
    },
    postConfirm: throttle(function(e) {
        console.log('提交封面', e);
        let params = e.detail.value;
        params.workerOrderResultId = this.data.workerOrderResultId
        console.log(params);
        _post(`/myTest/updateTestResultByWorkerId`, params).then(res => {
            console.log('提交封面返回值', res);
            dd.navigateTo({
                url: '/pages/mytest/test_list/test_list'
            })
        })
    }, 2000),

    onLoad() {
        this.getConfirm()
        dd.setNavigationBar({
            title: '项目基本信息录入',
            backgroundColor: '#142e4f',
            success() {},
            fail() {},
        });
    },
});